
export const HOOKS = [
  'beforeCreated',
  'created',
  'beforeMount',
  'mounted',
  'beforeUpdate',
  'updated',
  'beforeDestory',
  'destoryed'
]

let starts = {};
starts.data = function(parentVal, childVal){
  return childVal
}
// starts.computed = function(){}
// starts.watch = function(){}
// starts.methods = function(){}
// 遍历生命周期
HOOKS.forEach(hooks => {
  starts[hooks] = mergeHook
})

function mergeHook(parentValue, childValue){
  // {created: [a,b], data: [a,b]}
  if (childValue) {
    if (parentValue) {
      return parentValue.concat(childValue)
    } else {
      return [childValue]
    }
  } else {
    return parentValue
  }
}
export function mergeOptions(parent, child) {
  const options = {};
  for(let key in parent) {
    mergeField(key)
  }
  for(let key in child) {
    mergeField(key)
  }

  function mergeField(key){
    // 根据key  策略模式
    if (starts[key]) {
      options[key] = starts[key](parent[key], child[key])
    } else {
      options[key] = child[key]
    }
  }
  return options
}
